package com.mzj.saas.mservice.smartlock.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.lock.entity.SmartLockPwd;
import com.mzj.saas.mservice.smartlock.service.huixiangjia.SmartLockHxjService;
import com.mzj.saas.mservice.smartlock.service.ruanku.SmartLockService;
import com.mzj.saas.mservice.smartlock.vo.DevMacStateVO;
import com.mzj.saas.mservice.smartlock.vo.DevMacVO;
import com.mzj.saas.mservice.smartlock.vo.DynamicPasswordVO;
import com.mzj.saas.mservice.smartlock.vo.SmartLockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 测试智能锁接口
 */
@Controller
@RequestMapping("device/lock")
public class SmartLockTestController {

	@Autowired
	private SmartLockService smartLockService;

	@Autowired
	private SmartLockHxjService smartLockHxjService;
	
	/**
	 * 根据mac获取设备sn号
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@GetMapping("/getSnByMac")
	@ResponseBody
	public ResultBean<String> getSnByMac(@RequestHeader String accessToken,@RequestParam String devMac) {
		return smartLockService.getSnByMac(devMac);
	}
	
	/**
	 * 批量根据mac获取设备sn号
	 * @param accessToken
	 * @param devMacs
	 * @return
	 */
	@GetMapping("/batchGetSnByMac")
	@ResponseBody
	public ResultBean<List<DevMacVO>> batchGetSnByMac(@RequestHeader String accessToken,@RequestParam List<String> devMacs){
		return smartLockService.batchGetSnByMac(devMacs);
	}
	
	/**
	 * 获取设备状态
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@GetMapping("/getState")
	@ResponseBody
	public ResultBean<DevMacStateVO> getState(@RequestHeader String accessToken,@RequestParam String sn) {
		return smartLockService.getState(sn);
	}
	
	/**
	 * 批量获取设备状态
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/batchGetState")
	@ResponseBody
	public ResultBean<List<DevMacStateVO>> batchGetState(@RequestHeader String accessToken,@RequestParam List<String> sns) {
		return smartLockService.batchGetState(sns);
	}
	 
	/**
	 * 动态密码
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/getDynamicPassword")
	@ResponseBody
	public ResultBean<List<DynamicPasswordVO>> getDynamicPassword(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
		return smartLockService.getDynamicPassword(vo);
	}
   
	
	 /**
	  * 新增/修改密码
	  * @param accessToken
	  * @param vo
	  * @return
	  */
	 @PostMapping("/operationPassword")
	 @ResponseBody
	 public ResultBean<String> operationPassword(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
	       return smartLockService.operationPassword(vo);
	  }
	 
	 /**
	  * 冻结/解冻密码
	  * @param accessToken
	  * @param vo
	  * @return
	  */
	 @PostMapping("/freezeOrUnfreeze")
	 @ResponseBody
	 public ResultBean<String> freezeOrUnfreeze(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
	       return smartLockService.freezeOrUnfreeze(vo);
	 }
	 
	 /**
	  * 删除密码
	  * @param accessToken
	  * @param vo
	  * @return
	  */
	 @PostMapping("/clearPassword")
	 @ResponseBody
	 public ResultBean<String> clearPassword(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
	       return smartLockService.clearPassword(vo);
	 }
	 
	 /**
	  *新增/修改卡
	  * @param accessToken
	  * @param vo
	  * @return
	  */
	 @PostMapping("/operationCardPassword")
	 @ResponseBody
	 public ResultBean<String> operationCardPassword(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
	       return smartLockService.operationCardPassword(vo);
	 }
	 
	 /**
	  *冻结/解冻卡
	  * @param accessToken
	  * @param vo
	  * @return
	  */
	 @PostMapping("/freezeOrUnfreezeCard")
	 @ResponseBody
	 public ResultBean<String> freezeOrUnfreezeCard(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
	       return smartLockService.freezeOrUnfreezeCard(vo);
	 }
	 
	 /**
	  *删除卡
	  * @param accessToken
	  * @param vo
	  * @return
	  */
	 @PostMapping("/clearCard")
	 @ResponseBody
	 public ResultBean<String> clearCard(@RequestHeader String accessToken,@RequestBody SmartLockVO vo) {
	       return smartLockService.clearCard(vo);
	 }

	/**
	 * 批量获取设备状态
	 * @param accessToken
	 * @return
	 */
	@PostMapping("/test")
	@ResponseBody
	public ResultBean<String> test(@RequestHeader String accessToken) {
		/*SmartLockVO smartLockVO = new SmartLockVO();
		Date date = new Date();
		smartLockVO.setSn("CHypLNMd8rc=");
		SmartLockPwd smartLockPwd = new SmartLockPwd();
		smartLockPwd.setStartTime(new Date());
		Date date1 = new Date(date.getTime() + (1000 * 60 * 60 * 24));
		smartLockPwd.setEndTime(date1);
		smartLockPwd.setPassword("435321");
		return smartLockHxjService.authorizationPwd(smartLockVO,smartLockPwd);*/

	/*	SmartLockVO smartLockVO = new SmartLockVO();
		smartLockVO.setIdentification("fHZANvzmZcI=");
		return smartLockHxjService.deletePwd(smartLockVO, null);*/

		return smartLockHxjService.uploadFile(null, null);
	}

}
